package my.story.db;

import java.io.File;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import org.junit.Test;




public class ScanPicAndInsertDb {

	@Test
	public void scanAndIntoDb(){
		Connection conn = null;
		conn = DBUtils.getConnection();
		String dir = "D:/workspace/3.6/zhangxiangandzhousi"+"/WebContent/images";
		System.out.println(dir);
		File imageDir = new File(dir);
		File[] pics = imageDir.listFiles();
		PreparedStatement pst = null;
		try {
			pst = conn.prepareStatement("insert into piccomment(picname)values(?);");
			for(File pic:pics){
				String fileName = pic.getName();
				pst.setString(1, fileName);
				pst.addBatch();
			}
			pst.executeBatch();
			
		} catch (SQLException e) {
			e.printStackTrace();
		}
	
	}
	
}
